<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2017/10/30
 * Time: 10:35
 * 该模型类已经弃用，由明凯使用Java编写
 */
namespace app\api\model;

use my\Define;
use think\Db;
use think\Model;

class TripModel extends Model
{
    public function saveLocal($table,$data)
    {
        return Db::name($table)->insert($data);
    }

    public function createLiveLocalTable($table_name,$prefix = 'xm_')
    {
        $sql = "CREATE TABLE `$prefix$table_name` (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `driver_id` int(11) DEFAULT NULL COMMENT '司机id',
              `live_local` varchar(255) DEFAULT NULL COMMENT '实时坐标',
              `order_sn` varchar(50) DEFAULT NULL COMMENT '订单号',
              `distance` int(11) DEFAULT NULL COMMENT '和上次坐标相比的距离差',
              PRIMARY KEY (`id`),
              KEY `did_sn` (`driver_id`,`order_sn`)
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Db::execute($sql);
    }

    public function getLiveLocalInfo($table,$map=array(),$order='id desc',$field='*')
    {
        return Db::name($table)->where($map)->order($order)->field($field)->find();
    }
}